import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class elevator here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class elevator  extends object
{
    Zony z;
    int range,top,bottom;
    boolean stand=false;
    
    public elevator(int r){
        range=r;
    }
    
    protected void addedToWorld(World world)
    {
        setImage(((it)getWorld()).getElevator());
        z = (Zony) getWorld().getObjects(Zony.class).get(0);
        top = getY()-range;
        bottom=getY(); 
    }  
    
    public void act() 
    {
        stand = z.getY()<getY()-16;
        if(Math.abs(z.getX()-getX())<19 && z.getY()>top-30 && z.getY()==getY()-19){
            if(getY()!=top)setLocation(getX(),getY()-2);
        }else{
            if(getY()!=bottom)setLocation(getX(),getY()+2);
        }
        
    }    
    
    public boolean stand(){
        return stand;
    }
    
    
    
}
